<?php
include("../seguranca.php"); // Inclui o arquivo com o sistema de segurança
protegePagina(); // Chama a função que protege a página

if (isset($_POST["Placa"]))
	$Placa = $_POST["Placa"];

$dbconn = mysql_connect('localhost', 'root', '') or die("MySQL: Não foi possível conectar-se ao servidor.");
$banco = mysql_select_db('wisecar', $dbconn) or die("Banco Inexistente!");

$query = "SELECT * FROM veiculos WHERE placa = '".$Placa."'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
if (!$row)
	header("Location:erro.php?erro=placaInexistente");
mysql_free_result($result);
?>

<!DOCTYPE html lang="pt-BR">
<head>    
<link href="../style/esquema.css" rel="stylesheet">
<script type="text/javascript" src="../script/script.js"></script>
<meta charset="UTF-8">
<title>Wise-Car</title>
</head>

<body>
<div align="right" class="geral">
   	<div id="content" align="center">
    <div class="logoff">
    <a href="http://localhost/wisecar/view/index.php"><input class="botaoSair" type="button" value="Home"></a>
    <a href="http://localhost/wisecar/index.php"><input class="botaoSair" type="button" value="Logoff"></a>
    </div>
    <h1>Editar Ve&iacute;culo</h1>
	<h2>Edite os dados desejados:</h2>
    <form action="../controller/editarVeiculo.php" onSubmit="return validaEditar();" method="post">
    <table align="center" border="0">
    <tr>
    	<td></td>
        <td>
    		<table width="100%" cellpadding="0" cellspacing="0">
    		<tr>
            	<td width="140px">Dados Antigos</td>
                <td>Dados Atuais</td>
            </tr>
    		</table>
    	</td>
    </tr>
    <tr>
    	<td>
			<label for="Placa">Placa</label>
		</td><td>
			<input type="text" name="PlacaAntiga" value="<?php echo $row['Placa'];?>" id="PlacaAntiga" readonly maxlength="7" />
            <input type="text" name="Placa" id="editaPlaca" maxlength="8" />
		</td>
    </tr>
	<tr>
    	<td>  
			<label for="MarcaVeiculo">Marca do Veículo</label>
		</td><td>
        	<input type="text" name="MarcaAntiga" id="MarcaAntiga" value="<?php echo $row['Marca'];?>" readonly>
	  		<select name="Marca" id="Marca">
		  	<option selected value=""></option>
			<option value="1">Fiat</option>
			<option value="2">Chevrolet</option>
			<option value="3">Ford</option>
			<option value="4">GM</option>
			<option value="5">Renault</option>	
			<option value="6">Jac Motors</option>
			<option value="7">Peugeot</option>
			<option value="8">KIA</option>
	  		</select>
  		</td>
	</tr>
  	<tr>
    	<td>
			<label for="ModeloVeiculo">Modelo do Veículo</label>
		</td><td>
  			<input type="text" name="ModeloAntigo" id="ModeloAntigo" value="<?php echo $row['Modelo'];?>" readonly/>
  			<input type="text" name="Modelo" id="Modelo" />
  		</td>
	</tr>
    <tr>
  		<td>
	  		<label for="AnoModelo">Ano do Modelo</label>
		</td><td>
	  		<input type="text" name="AnoModeloAntigo" id="AnoModeloAntigo" maxlength="4" readonly value="<?php echo $row['Ano_Modelo'];?>" onKeyPress="return isNumber(event)"/>
	  		<input type="text" name="AnoModelo" id="AnoModelo" maxlength="4" onKeyPress="return isNumber(event)"/>            
		</td>
	</tr>
	<tr>
  		<td>
	  		<label for="AnoFabricacao">Ano de Fabricação</label>
		</td><td>
	  		<input type="text" name="AnoFabricacaoAntigo" id="AnoFabricacaoAntigo" value="<?php echo $row['Ano_Fabricacao'];?>" readonly maxlength="4" onKeyPress="return isNumber(event)"/>
	  		<input type="text" name="AnoFabricacao" id="AnoFabricacao" maxlength="4" onKeyPress="return isNumber(event)"/>            
		</td>
	</tr>
	<tr>
  		<td>
	  		<label for="Cor">Cor do Veículo</label>
		</td><td>
			<input type="text" name="CorAntiga" id="CorAntiga" value="<?php echo $row['Cor'];?>" readonly>        
	  		<select name="Cor" id="Cor">
		  	<option value="1">Branco</option>
		  	<option value="2">Preto</option>
		  	<option value="3">Vermelho</option>
		  	<option value="4">Azul</option>
		  	<option value="5">Verde</option>	
		  	<option value="6">Prata</option>
		  	<option value="7">Amarelo</option>
		  	<option selected value=""></option>
	  		</select>
  		</td>
	</tr>
	<tr>
  		<td>
	  		<label for="Combustivel">Combustível</label>
	  	</td><td>
			<input type="text" name="CombustivelAntigo" id="CombustivelAntigo" value="<?php echo $row['Combustivel'];?>" readonly> 
	  		<select name="Combustivel" id="Combustivel">
		  	<option value="1">Gasolina</option>
		  	<option value="2">Álcool</option>
		  	<option value="3">Bicombustível</option>
		  	<option value="4">GNV</option>
		  	<option value="6">Diesel</option>
			<option value="7">Tricombustível</option>
			<option selected="selected" value=""></option>
			</select>
  		</td>
	</tr>
    <tr>
    	<td colspan="2">
    	    <label for="Opcionais">Opcionais</label>:<br/><br/>
			<textarea id="OpcionaisAntigo" name="OpcionaisAntigo" cols="30" rows="3" readonly><?php echo $row['Opcionais'];?></textarea>
            <textarea id="Opcionais" name="Opcionais" cols="30" rows="3" ></textarea>
    	</td>
    </tr>
    <tr>
		<td colspan="2" align="center">
		  <a href="gerenciarVeiculos.php"><input type="button" value="Voltar"></a>
          &nbsp;
		  <input type="submit" value="Enviar">
		</td>
	</tr>
	</table>
    </form>
	</div>
</div>
</body>
</html>